﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 实验二._1
{
    class Program
    {
        static void Main(string[] args)
        {
            Czpoint P1 = new Czpoint(1, 2);
            Console.WriteLine($"创建P1{P1.getname()}");
            Czpoint P2 = new Czpoint(3, 3);
            Console.WriteLine($"创建P2{P2.getname()}");
            Console.Write("判断相等：");
            Isequal(P1, P2);
            Console.WriteLine($"移动前P1{P1.getname()}，P2{P2.getname()}");
            P1.Move(2, 1);
            Console.WriteLine($"移动后P1{P1.getname()}，P2{P2.getname()}");
            Console.Write("判断相等：");
            Isequal(P1, P2);
            Czline L1 = new Czline(1, 0);
            Console.WriteLine($"创建L1:{L1.getname()}");
            Czpoint P3 = new Czpoint(2, 6);
            Console.WriteLine($"创建P3{P3.getname()}");
            Console.Write("判断P3是否在直线L1上：");
            L1.contains(P3);
            Czline L2 = new Czline(P2, P3);
            Console.WriteLine($"创建L2:{L2.getname()}");
            Console.Write("判断P3是否在直线L2上：");
            L2.contains(P3);
            Console.WriteLine($"移动前L2:{L2.getname()}");
            L2.Move(-1, 0);
            Console.WriteLine($"移动后L2:{L2.getname()}");
            Console.Write("判断P3是否在直线上L2：");
            L2.contains(P3);
            Console.ReadKey();




        }
        public static void Isequal(Czpoint p1, Czpoint p2)
        {
            if (p1 == p2)
                Console.WriteLine("两点相等");
            else
                Console.WriteLine("两点不相等");

        }
    }
    class Czpoint//点类
    {
        private string pointname;
        private int x;
        private int y;
        public int Y { get { return y; } set { y = value; } }
        public int X { get { return x; } set { x = value; } }
        public string getname()
        {
            return pointname;
        }
        public Czpoint(int x, int y)
        {
            this.x = x;
            this.y = y;
            pointname = string.Format("({0},{1}) ", x, y);
        }
        public void Move(int x_, int y_)
        {
            x += x_;
            y += y_;
            pointname = string.Format("({0},{1}) ", x, y);
        }
        public static bool operator ==(Czpoint a, Czpoint b)
        {
            if (a.x == b.x && a.y == b.y)
            {
                return true;
            }
            else return false;
        }
        public static bool operator !=(Czpoint a, Czpoint b)
        {
            if (a == b)
                return false;
            else return true;
        }


    }
    class Czline//直线类
    {
        private int a;//斜率
        private int b;//截距
        public int A { get { return a; } set { a = value; } }
        public int B { get { return b; } set { b = value; } }
        public string linename;
        public string getname()
        {
            return linename;
        }
        public Czline(int a, int b)
        {
            this.A = a;
            this.B = b;
            linename = string.Format("y={0}x+{1} ", a, b);
        }
        public Czline(Czpoint p1, Czpoint p2)
        {
            this.A = (p2.Y - p1.Y) / (p2.X - p1.X);
            this.B = p1.Y - this.A * p1.X;
            linename = string.Format("y={0}x+{1} ", a, b);
        }



        public void Move(int x_distance, int y_distance)//参数：水平方向移动距离，竖直方向移动距离
        {
            B = -x_distance * this.A + B + y_distance;//计算截距
            linename = string.Format("y={0}x+{1} ", a, b);
        }
        public bool contains(Czpoint p)
        {
            if (p.Y == p.X * a + b)
            {
                Console.WriteLine("点在直线上！");
                return true;
            }
            else
            {
                Console.WriteLine("点不在直线上！");
                return false;
            }

        }
    }
}
